#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int c[10];
int num[1000050];
int main(void){
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        memset(c,'\0',sizeof(c));
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++){
            scanf("%d",&c[i]);
        }
        int t=0;
        sort(c,c+n);
        do{
            int sum=0;
            if(c[0]==0){
                continue;
            }
            for(int i=0;i<n;i++){
                sum=10*sum+c[i];
            }
            num[t++]=sum;
        }while(next_permutation(c,c+n));
        int x,k;
        while(m--){
            scanf("%d%d",&x,&k);
            int i;
            for(i=0;i<t;i++){
                if((num[i]+x)%k==0){
                    printf("%d\n",num[i]);
                    break;
                }
            }
            if(i==t){
                printf("None\n");
            }
        }
    }
    return 0;
}
